#include "stdafx.h"
#include "TestStlContainerIterator.h"
#include <Utility/VectorIterator.h>
#include <vector>

#ifdef WIN32
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif //_DEBUG
#endif //WIND32

namespace serika
{
	namespace test
	{
		CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestStlContainerIterator, "TestUtility");

		TestStlContainerIterator::TestStlContainerIterator()
		{
		}

		TestStlContainerIterator::~TestStlContainerIterator()
		{
		}

		void TestStlContainerIterator::TestRunWell()
		{
			std::vector<int> intList;
			for (int i = 0; i < 10; ++i)
			{
				intList.push_back(i);
			}

			ut::VectorReadOnlyIterator<int> vectorReadonlyIterator(intList);

			int desire = 0;
			while (vectorReadonlyIterator.HasNext())
			{
				int curr = vectorReadonlyIterator.GetCurrent();
				CPPUNIT_ASSERT_EQUAL(desire, curr);
				++desire;
				vectorReadonlyIterator.Next();
			}

			ut::VectorIterator<int> vecIter(intList);
			while (vecIter.HasNext())
			{
				int& curr = vecIter.GetCurrent();
				curr = 10 - curr;
				vecIter.Next();
			}

			ut::VectorReadOnlyIterator<int> vecRIter(intList);
			desire = 10;
			while (vecRIter.HasNext())
			{
				int curr = vecRIter.GetCurrent();
				CPPUNIT_ASSERT_EQUAL(desire, curr);
				--desire;
				vecRIter.Next();
			}
		}
	}
}
